import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
// Vue.filter('time', function(val) {
//     var Y = val.getFullYear();
//     var M = val.getMonth() + 1;
//     var D = val.getDate();
//     var H = val.getHours();
//     var m = val.getMinutes().toString().padStart(2, '0')
//     var s = val.getSeconds().toString().padStart(2, '0')
//     return Y + '/' + M + '/' + D + ' ' + H + ':' + m + ':' + s
// })
import {
    Message,
    Notification
} from 'element-ui'

Vue.prototype.$notify = Notification;
Vue.prototype.$message = Message;
Vue.filter('times', function(val) {
    var data = new Date(val)
    var a = data.toLocaleDateString()
    var v = data.toLocaleTimeString()
    return a + v
})
router.beforeEach((to, from, next) => {
    // console.log(to);
    document.title = to.name
    next()
    if (to.path != '/login') {
        if (sessionStorage.getItem('admin')) {
            // next()
        } else {
            next('/login')
            return
        }
    }
    const val = JSON.parse(sessionStorage.getItem('admin'))
    console.log(val);
    if (val !== null) {
        const timestamp = new Date() - val.time;
        console.log(timestamp);
        if (timestamp > val.expire) {
            sessionStorage.removeItem("admin")
            next('/login')
            return null;
        }
    }
    // next()
})
Vue.config.productionTip = false
import '../src/utils/request.js'
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios'

Vue.prototype.axios = axios
new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')